#ifndef BSP_CAN_H
#define BSP_CAN_H
#include "can.h"
#include "bsp_cap.h"


/*************/
#define CAN_CHASSIS_ALL_ID 0x200
#define CAN_3508_M1_ID 0x201
#define CAN_3508_M2_ID 0x202
#define CAN_3508_M3_ID 0x203
#define CAN_3508_M4_ID 0x204

#define CAN_helm_M1_ID 0x205
#define CAN_helm_M2_ID 0x206
#define CAN_helm_M3_ID 0x207
#define CAN_helm_M4_ID 0x208

#define CAN_AMMO_ALL_ID 0x200
#define CAN_2006_M1_ID 0x201   //

#define CAN_GIMBAL_ALL_ID 0x280
#define CAN_LK_M1_ID 0x141
#define CAN_LK_M2_ID 0x142
#define CAN_LK_M3_ID 0x143

#define CAN_COMMUNITE_ID_1 0x301
#define CAN_COMMUNITE_ID_2 0x302
#define CAN_COMMUNITE    hcan1


extern CAN_HandleTypeDef hcan1;
extern CAN_HandleTypeDef hcan2;

/***********/
typedef struct
{
	    int16_t last_ecd;
    uint16_t ecd;
    fp32 speed_rpm;
    int16_t given_current;
    uint8_t temperate;
	
}motor_measure_t;

#define get_motor_measure(ptr, data)                                    \
    {                                                                   \
        (ptr)->last_ecd = (ptr)->ecd;                                   \
        (ptr)->ecd = (uint16_t)((data)[0] << 8 | (data)[1]);            \
        (ptr)->speed_rpm = 	(int16_t)((data)[2] << 8 | (data)[3]);      \
        (ptr)->given_current = (uint16_t)((data)[4] << 8 | (data)[5]);  \
        (ptr)->temperate = (data)[6];                                   \
    }

#define motor_measure_LK(ptr, data)                                 						\
    {                                                                   				\
        (ptr)->last_ecd = 			(ptr)->ecd;                             				\
        (ptr)->ecd = 						(uint16_t)((data)[7] << 8 | (data)[6]); 				\
        (ptr)->speed_rpm = 			((int16_t)((data)[5] << 8 | (data)[4]))/60.0f;	\
        (ptr)->given_current = 	(uint16_t)((data)[3] << 8 | (data)[2]); 				\
        (ptr)->temperate = 			(data)[1];                              				\
    }
/****************/
extern void can_filter_init(void);
extern void Motor_2006_Ecd(motor_measure_t data_in,int8_t *data_con,int32_t *data_out);
extern void CAN_CMD_BASE(CAN_HandleTypeDef* hcan,uint32_t id, int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4);
/****************/

extern motor_measure_t motor_measure_gimbal[3];//0:yaw 1:pitch 
extern motor_measure_t motor_measure_shoot[4];// 0:dial 1:barrel

extern int32_t barrel_angle;
extern int32_t dial_angle;

#endif
